# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: app_interface.py
Author: kij
Create Date: 2021/2/28
-------------------------------------------------
"""
from app import AppClient


# 校验参数是否正确
def argv_verification(ip, port, ):
	if not ip or not port:
		return False, 'IP地址和端口未输入'
	else:
		return True, '开始链接'


def auth(ip, port, user_name, user_password):
	app_client = AppClient(ip, port)
	response = app_client.auth(user_name, user_password)

	if response.get('status_code') == 200:
		app_client.user_name = user_name
		app_client.user_password = user_password
		# app_client.terminal_display = "[%s]>>:" % app_client.username
		app_client.current_dir = "\\"
		return True, app_client
	else:
		return False, response.get('status_msg')


def parameter_check(args, min_args=None, max_args=None, exact_args=None):
	"""检查参数信息，最大和最少参数"""
	if min_args:
		if len(args) < min_args:
			return False, "最少需要 %s 个参数，实际传入 %s 个参数。" % (min_args, len(args))
	if max_args:
		if len(args) > max_args:
			return False, "最大需要 %s 个参数，实际传入 %s 个参数。" % (max_args, len(args))
	if exact_args:
		if len(args) != exact_args:
			return False, "实际需要 %s 个参数，实际传入 %s 个参数。" % (exact_args, len(args))
	return True, ""


def download_file(cmd_args, user):
	file_name = cmd_args[0]
	response = user._get('get', file_name)
	print(response)
	if response.get('status_code') == 301:
		user.get_file(file_name,response)
		return False, response
	else:
		return False, response.get('status_msg')

def show_dir(user):
	response = user._ls('ls')
	print(response)
	if response.get('status_code') == 302:
		cmd_result_size = response.get('cmd_result_size')
		return True, user.get_folder(cmd_result_size)
	else:
		return False, response.get('status_msg')